package com.carol.lmsbe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.carol.lmsbe.entity.EquipmentBorrow;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 设备借还Mapper接口
 */
@Mapper
public interface EquipmentBorrowMapper extends BaseMapper<EquipmentBorrow> {

    /**
     * 根据设备ID查询借还记录
     */
    @Select("SELECT eb.*, e.name as equipment_name, e.code as equipment_code " +
            "FROM equipment_borrow eb " +
            "LEFT JOIN equipment e ON eb.equipment_id = e.id " +
            "WHERE eb.equipment_id = #{equipmentId}")
    List<EquipmentBorrow> selectByEquipmentId(@Param("equipmentId") Long equipmentId);

    /**
     * 根据借用人ID查询借还记录
     */
    @Select("SELECT eb.*, e.name as equipment_name, e.code as equipment_code " +
            "FROM equipment_borrow eb " +
            "LEFT JOIN equipment e ON eb.equipment_id = e.id " +
            "WHERE eb.borrower_id = #{borrowerId}")
    List<EquipmentBorrow> selectByBorrowerId(@Param("borrowerId") Long borrowerId);

    /**
     * 根据状态查询借还记录
     */
    @Select("SELECT eb.*, e.name as equipment_name, e.code as equipment_code " +
            "FROM equipment_borrow eb " +
            "LEFT JOIN equipment e ON eb.equipment_id = e.id " +
            "WHERE eb.status = #{status}")
    List<EquipmentBorrow> selectByStatus(@Param("status") String status);
}
